package com.t2t.top.framework.diamond;

import com.t2t.top.framework.util.ToolsIoUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by yangpengfei on 2016/9/5.
 */
public class PropertiesUtils {
    static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);

    public static Properties toProperties(String config) {
        InputStream in = null;
        try {
            in = new ByteArrayInputStream(config.getBytes("UTF-8"));
        } catch (Exception e) {
            logger.error("读取失败", e);
        }
        return toProperties(in);
    }

    public static Properties toProperties(InputStream in) {
        Properties properties = new Properties();
        try {
            properties.load(in);
            return properties;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            ToolsIoUtils.closeQuietly(in);
        }
        return properties;
    }
}
